package com.wkhyapp.lm.view;

import android.os.Build;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.base.BaseActivity;
import com.wkhyapp.lm.base.SuperActivity;
import com.wkhyapp.lm.contract.AdminPresenter;
import com.wkhyapp.lm.contract.AdminView;
import com.wkhyapp.lm.utils.StatusBarFontUtil;

import butterknife.BindView;

public class AdminActivity extends SuperActivity<AdminPresenter> implements AdminView{

    @BindView(R.id.all_rl)
    RelativeLayout allRl;
    @BindView(R.id.xn_rl)
    RelativeLayout xn_rl;
    @BindView(R.id.kt_rl)
    RelativeLayout kt_rl;
    @BindView(R.id.nums_et)
    EditText nums_et;
    @BindView(R.id.zjlll)
    Button zjlll;
    @BindView(R.id.zjrd)
    Button zjrd;
    @BindView(R.id.back_iv)
    ImageView back_iv;
    @BindView(R.id.zq_but)
    Button zqBut;
    @BindView(R.id.xcurl_et)
    EditText xcurl_et;
    @BindView(R.id.goods_et)
    EditText goods_et;
    @BindView(R.id.sdid_et)
    EditText sdid_et;

    @Override
    public void initUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            translucentStatusBar();
        }
        StatusBarFontUtil.setLightStatusBarColor(this);
    }

    @Override
    protected void initListener() {
        allRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(SYSJActivity.class);
            }
        });
        xn_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(XNSJActivity.class);
            }
        });
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        kt_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTo(KTSJActivity.class);
            }
        });

        zjlll.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if("".equals(nums_et.getText().toString())){
                    TToast("请输入增加数量");
                    return;
                }
                showLoad("正在添加..");
             mPresenter.addviews(Integer.parseInt( nums_et.getText().toString()));
            }
        });

        zjrd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if("".equals(nums_et.getText().toString())){
                    TToast("请输入增加数量");
                    return;
                }
                showLoad("正在添加..");
                mPresenter.addHost(Integer.parseInt( nums_et.getText().toString()));
            }
        });


        zqBut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if("".equals(sdid_et.getText().toString())){
                    TToast("请输入商家ID");
                    return;
                }
                if("".equals(goods_et.getText().toString())){
                    TToast("请输入抓取数量");
                    return;
                }
                if("".equals(xcurl_et.getText().toString())){
                    TToast("请输入相册地址");
                    return;
                }
                showLoad("开始抓取");
                mPresenter.zhuaqu(Integer.parseInt(sdid_et.getText().toString()),Integer.parseInt(goods_et.getText().toString()),xcurl_et.getText().toString().trim());
            }


        });

    }

    @Override
    protected void afterCreate() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_admin;
    }


    @Override
    public void setSucc() {
        dismissLoad();
        TToast("操作成功");
    }

    @Override
    public void getSucc(String msg) {
        dismissLoad();
        TToast(msg);
    }

    @Override
    protected AdminPresenter createPresenter() {
        return mPresenter = new AdminPresenter(this);
    }
}
